using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Globalization;
using System.Windows.Forms;
using C1.Win.C1FlexGrid;

//PCS namespaces
using PCSComUtils.Admin.DS;
using PCSComUtils.Admin.BO;
using PCSComUtils.Common;
using PCSComUtils.PCSExc;
using PCSUtils.Log;
using PCSUtils.Utils;

namespace PCSUtils.Admin
{
	/// <summary>
	/// Summary description for GrantRoleProtect.
	/// </summary>
	public class GrantRoleProtect : System.Windows.Forms.Form
	{
		#region Declaration
		
		#region System Generated
		
		private Panel pnlRoleProtection;
		private GroupBox grpProtection;
		private GroupBox grpRole;
		private Button btnSave;
		private Button btnClose;	// Store status of ProtectionTree
		private C1FlexGrid c1FlexGridProtect;
		private Splitter splitter1;
		private C1FlexGrid c1FlexGridRole;
		private System.Windows.Forms.Button btnHelp;
		
		#endregion System Generated

		private const string THIS = "PCSUtils.Admin.GrantRoleProtect";
		// Constant declare
		private const int INT_START = 1;
		// private const int NUMBER_COLUMN = 8;
		private const int COLUMN_WIDTH_BASE = 30;
		// const position of column
		const int INT_POS_TREE = 1;
		const int INT_POS_ALL = 2;
		const int INT_POS_VIEW = 3;
		const int INT_POS_ADD = 4;
		const int INT_POS_EDIT = 5;
		const int INT_POS_DELETE = 6;
		const int INT_POS_PRINT = 7;
		const int INT_POS_MENU_ENTRY = 8;
		const int INT_POS_PARENT_CHILD = 9;
		const int INT_POS_PERMISSION = 10;

		private const int ACTION_NONE = 0;
		private const int ACTION_VIEW = 1;
		private const int ACTION_ADD = 2;
		private const int ACTION_EDIT = 4;
		private const int ACTION_DELETE = 8;
		private const int ACTION_PRINT = 16;
		private const int ACTION_ALL = 31;
		
		private bool blnIsModified = false;
		
		private int intCurrentRow = 0;
		private DataSet dstProtection = new DataSet();		
		private ArrayList arrSysMenuEntry = new ArrayList();

		private string NAME_COL = string.Empty;
		private string DESC_COL = string.Empty;

		#endregion

		#region Windows Form Designer generated code

		public GrantRoleProtect()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(GrantRoleProtect));
			this.pnlRoleProtection = new System.Windows.Forms.Panel();
			this.grpProtection = new System.Windows.Forms.GroupBox();
			this.c1FlexGridProtect = new C1.Win.C1FlexGrid.C1FlexGrid();
			this.splitter1 = new System.Windows.Forms.Splitter();
			this.grpRole = new System.Windows.Forms.GroupBox();
			this.c1FlexGridRole = new C1.Win.C1FlexGrid.C1FlexGrid();
			this.btnSave = new System.Windows.Forms.Button();
			this.btnClose = new System.Windows.Forms.Button();
			this.btnHelp = new System.Windows.Forms.Button();
			this.pnlRoleProtection.SuspendLayout();
			this.grpProtection.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.c1FlexGridProtect)).BeginInit();
			this.grpRole.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.c1FlexGridRole)).BeginInit();
			this.SuspendLayout();
			// 
			// pnlRoleProtection
			// 
			this.pnlRoleProtection.AccessibleDescription = resources.GetString("pnlRoleProtection.AccessibleDescription");
			this.pnlRoleProtection.AccessibleName = resources.GetString("pnlRoleProtection.AccessibleName");
			this.pnlRoleProtection.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("pnlRoleProtection.Anchor")));
			this.pnlRoleProtection.AutoScroll = ((bool)(resources.GetObject("pnlRoleProtection.AutoScroll")));
			this.pnlRoleProtection.AutoScrollMargin = ((System.Drawing.Size)(resources.GetObject("pnlRoleProtection.AutoScrollMargin")));
			this.pnlRoleProtection.AutoScrollMinSize = ((System.Drawing.Size)(resources.GetObject("pnlRoleProtection.AutoScrollMinSize")));
			this.pnlRoleProtection.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("pnlRoleProtection.BackgroundImage")));
			this.pnlRoleProtection.Controls.Add(this.grpProtection);
			this.pnlRoleProtection.Controls.Add(this.splitter1);
			this.pnlRoleProtection.Controls.Add(this.grpRole);
			this.pnlRoleProtection.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("pnlRoleProtection.Dock")));
			this.pnlRoleProtection.Enabled = ((bool)(resources.GetObject("pnlRoleProtection.Enabled")));
			this.pnlRoleProtection.Font = ((System.Drawing.Font)(resources.GetObject("pnlRoleProtection.Font")));
			this.pnlRoleProtection.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("pnlRoleProtection.ImeMode")));
			this.pnlRoleProtection.Location = ((System.Drawing.Point)(resources.GetObject("pnlRoleProtection.Location")));
			this.pnlRoleProtection.Name = "pnlRoleProtection";
			this.pnlRoleProtection.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("pnlRoleProtection.RightToLeft")));
			this.pnlRoleProtection.Size = ((System.Drawing.Size)(resources.GetObject("pnlRoleProtection.Size")));
			this.pnlRoleProtection.TabIndex = ((int)(resources.GetObject("pnlRoleProtection.TabIndex")));
			this.pnlRoleProtection.Text = resources.GetString("pnlRoleProtection.Text");
			this.pnlRoleProtection.Visible = ((bool)(resources.GetObject("pnlRoleProtection.Visible")));
			// 
			// grpProtection
			// 
			this.grpProtection.AccessibleDescription = resources.GetString("grpProtection.AccessibleDescription");
			this.grpProtection.AccessibleName = resources.GetString("grpProtection.AccessibleName");
			this.grpProtection.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("grpProtection.Anchor")));
			this.grpProtection.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("grpProtection.BackgroundImage")));
			this.grpProtection.Controls.Add(this.c1FlexGridProtect);
			this.grpProtection.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("grpProtection.Dock")));
			this.grpProtection.Enabled = ((bool)(resources.GetObject("grpProtection.Enabled")));
			this.grpProtection.Font = ((System.Drawing.Font)(resources.GetObject("grpProtection.Font")));
			this.grpProtection.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("grpProtection.ImeMode")));
			this.grpProtection.Location = ((System.Drawing.Point)(resources.GetObject("grpProtection.Location")));
			this.grpProtection.Name = "grpProtection";
			this.grpProtection.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("grpProtection.RightToLeft")));
			this.grpProtection.Size = ((System.Drawing.Size)(resources.GetObject("grpProtection.Size")));
			this.grpProtection.TabIndex = ((int)(resources.GetObject("grpProtection.TabIndex")));
			this.grpProtection.TabStop = false;
			this.grpProtection.Text = resources.GetString("grpProtection.Text");
			this.grpProtection.Visible = ((bool)(resources.GetObject("grpProtection.Visible")));
			// 
			// c1FlexGridProtect
			// 
			this.c1FlexGridProtect.AccessibleDescription = resources.GetString("c1FlexGridProtect.AccessibleDescription");
			this.c1FlexGridProtect.AccessibleName = resources.GetString("c1FlexGridProtect.AccessibleName");
			this.c1FlexGridProtect.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("c1FlexGridProtect.Anchor")));
			this.c1FlexGridProtect.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("c1FlexGridProtect.BackgroundImage")));
			this.c1FlexGridProtect.ColumnInfo = resources.GetString("c1FlexGridProtect.ColumnInfo");
			this.c1FlexGridProtect.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("c1FlexGridProtect.Dock")));
			this.c1FlexGridProtect.Enabled = ((bool)(resources.GetObject("c1FlexGridProtect.Enabled")));
			this.c1FlexGridProtect.Font = ((System.Drawing.Font)(resources.GetObject("c1FlexGridProtect.Font")));
			this.c1FlexGridProtect.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("c1FlexGridProtect.ImeMode")));
			this.c1FlexGridProtect.Location = ((System.Drawing.Point)(resources.GetObject("c1FlexGridProtect.Location")));
			this.c1FlexGridProtect.Name = "c1FlexGridProtect";
			this.c1FlexGridProtect.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("c1FlexGridProtect.RightToLeft")));
			this.c1FlexGridProtect.Rows.Count = 1;
			this.c1FlexGridProtect.Size = ((System.Drawing.Size)(resources.GetObject("c1FlexGridProtect.Size")));
			this.c1FlexGridProtect.Styles = new C1.Win.C1FlexGrid.CellStyleCollection(@"Normal{Font:Microsoft Sans Serif, 8.25pt;}	Fixed{BackColor:Control;ForeColor:ControlText;Border:Flat,1,ControlDark,Both;}	Highlight{BackColor:Highlight;ForeColor:HighlightText;}	Search{BackColor:Highlight;ForeColor:HighlightText;}	Frozen{BackColor:Beige;}	EmptyArea{BackColor:AppWorkspace;Border:Flat,1,ControlDarkDark,Both;}	GrandTotal{BackColor:Black;ForeColor:White;}	Subtotal0{BackColor:ControlDarkDark;ForeColor:White;}	Subtotal1{BackColor:ControlDarkDark;ForeColor:White;}	Subtotal2{BackColor:ControlDarkDark;ForeColor:White;}	Subtotal3{BackColor:ControlDarkDark;ForeColor:White;}	Subtotal4{BackColor:ControlDarkDark;ForeColor:White;}	Subtotal5{BackColor:ControlDarkDark;ForeColor:White;}	");
			this.c1FlexGridProtect.TabIndex = ((int)(resources.GetObject("c1FlexGridProtect.TabIndex")));
			this.c1FlexGridProtect.Text = resources.GetString("c1FlexGridProtect.Text");
			this.c1FlexGridProtect.Tree.Column = 1;
			this.c1FlexGridProtect.Tree.Indent = 10;
			this.c1FlexGridProtect.Visible = ((bool)(resources.GetObject("c1FlexGridProtect.Visible")));
			this.c1FlexGridProtect.Click += new System.EventHandler(this.c1FlexGridProtect_Click);
			this.c1FlexGridProtect.KeyUp += new System.Windows.Forms.KeyEventHandler(this.c1FlexGridProtect_KeyUp);
			// 
			// splitter1
			// 
			this.splitter1.AccessibleDescription = resources.GetString("splitter1.AccessibleDescription");
			this.splitter1.AccessibleName = resources.GetString("splitter1.AccessibleName");
			this.splitter1.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("splitter1.Anchor")));
			this.splitter1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("splitter1.BackgroundImage")));
			this.splitter1.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("splitter1.Dock")));
			this.splitter1.Enabled = ((bool)(resources.GetObject("splitter1.Enabled")));
			this.splitter1.Font = ((System.Drawing.Font)(resources.GetObject("splitter1.Font")));
			this.splitter1.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("splitter1.ImeMode")));
			this.splitter1.Location = ((System.Drawing.Point)(resources.GetObject("splitter1.Location")));
			this.splitter1.MinExtra = ((int)(resources.GetObject("splitter1.MinExtra")));
			this.splitter1.MinSize = ((int)(resources.GetObject("splitter1.MinSize")));
			this.splitter1.Name = "splitter1";
			this.splitter1.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("splitter1.RightToLeft")));
			this.splitter1.Size = ((System.Drawing.Size)(resources.GetObject("splitter1.Size")));
			this.splitter1.TabIndex = ((int)(resources.GetObject("splitter1.TabIndex")));
			this.splitter1.TabStop = false;
			this.splitter1.Visible = ((bool)(resources.GetObject("splitter1.Visible")));
			// 
			// grpRole
			// 
			this.grpRole.AccessibleDescription = resources.GetString("grpRole.AccessibleDescription");
			this.grpRole.AccessibleName = resources.GetString("grpRole.AccessibleName");
			this.grpRole.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("grpRole.Anchor")));
			this.grpRole.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("grpRole.BackgroundImage")));
			this.grpRole.Controls.Add(this.c1FlexGridRole);
			this.grpRole.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("grpRole.Dock")));
			this.grpRole.Enabled = ((bool)(resources.GetObject("grpRole.Enabled")));
			this.grpRole.Font = ((System.Drawing.Font)(resources.GetObject("grpRole.Font")));
			this.grpRole.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("grpRole.ImeMode")));
			this.grpRole.Location = ((System.Drawing.Point)(resources.GetObject("grpRole.Location")));
			this.grpRole.Name = "grpRole";
			this.grpRole.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("grpRole.RightToLeft")));
			this.grpRole.Size = ((System.Drawing.Size)(resources.GetObject("grpRole.Size")));
			this.grpRole.TabIndex = ((int)(resources.GetObject("grpRole.TabIndex")));
			this.grpRole.TabStop = false;
			this.grpRole.Text = resources.GetString("grpRole.Text");
			this.grpRole.Visible = ((bool)(resources.GetObject("grpRole.Visible")));
			// 
			// c1FlexGridRole
			// 
			this.c1FlexGridRole.AccessibleDescription = resources.GetString("c1FlexGridRole.AccessibleDescription");
			this.c1FlexGridRole.AccessibleName = resources.GetString("c1FlexGridRole.AccessibleName");
			this.c1FlexGridRole.AllowEditing = false;
			this.c1FlexGridRole.AllowSorting = C1.Win.C1FlexGrid.AllowSortingEnum.None;
			this.c1FlexGridRole.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("c1FlexGridRole.Anchor")));
			this.c1FlexGridRole.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("c1FlexGridRole.BackgroundImage")));
			this.c1FlexGridRole.ColumnInfo = resources.GetString("c1FlexGridRole.ColumnInfo");
			this.c1FlexGridRole.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("c1FlexGridRole.Dock")));
			this.c1FlexGridRole.Enabled = ((bool)(resources.GetObject("c1FlexGridRole.Enabled")));
			this.c1FlexGridRole.Font = ((System.Drawing.Font)(resources.GetObject("c1FlexGridRole.Font")));
			this.c1FlexGridRole.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("c1FlexGridRole.ImeMode")));
			this.c1FlexGridRole.Location = ((System.Drawing.Point)(resources.GetObject("c1FlexGridRole.Location")));
			this.c1FlexGridRole.Name = "c1FlexGridRole";
			this.c1FlexGridRole.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("c1FlexGridRole.RightToLeft")));
			this.c1FlexGridRole.Rows.Count = 1;
			this.c1FlexGridRole.SelectionMode = C1.Win.C1FlexGrid.SelectionModeEnum.Row;
			this.c1FlexGridRole.Size = ((System.Drawing.Size)(resources.GetObject("c1FlexGridRole.Size")));
			this.c1FlexGridRole.Styles = new C1.Win.C1FlexGrid.CellStyleCollection(@"Normal{Font:Microsoft Sans Serif, 8.25pt;}	Fixed{BackColor:Control;ForeColor:ControlText;Border:Flat,1,ControlDark,Both;}	Highlight{BackColor:Highlight;ForeColor:HighlightText;}	Search{BackColor:Highlight;ForeColor:HighlightText;}	Frozen{BackColor:Beige;}	EmptyArea{BackColor:AppWorkspace;Border:Flat,1,ControlDarkDark,Both;}	GrandTotal{BackColor:Black;ForeColor:White;}	Subtotal0{BackColor:ControlDarkDark;ForeColor:White;}	Subtotal1{BackColor:ControlDarkDark;ForeColor:White;}	Subtotal2{BackColor:ControlDarkDark;ForeColor:White;}	Subtotal3{BackColor:ControlDarkDark;ForeColor:White;}	Subtotal4{BackColor:ControlDarkDark;ForeColor:White;}	Subtotal5{BackColor:ControlDarkDark;ForeColor:White;}	");
			this.c1FlexGridRole.TabIndex = ((int)(resources.GetObject("c1FlexGridRole.TabIndex")));
			this.c1FlexGridRole.Text = resources.GetString("c1FlexGridRole.Text");
			this.c1FlexGridRole.Visible = ((bool)(resources.GetObject("c1FlexGridRole.Visible")));
			this.c1FlexGridRole.BeforeRowColChange += new C1.Win.C1FlexGrid.RangeEventHandler(this.c1FlexGridRole_BeforeRowColChange);
			this.c1FlexGridRole.AfterRowColChange += new C1.Win.C1FlexGrid.RangeEventHandler(this.c1FlexGridRole_AfterRowColChange);
			// 
			// btnSave
			// 
			this.btnSave.AccessibleDescription = resources.GetString("btnSave.AccessibleDescription");
			this.btnSave.AccessibleName = resources.GetString("btnSave.AccessibleName");
			this.btnSave.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("btnSave.Anchor")));
			this.btnSave.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btnSave.BackgroundImage")));
			this.btnSave.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("btnSave.Dock")));
			this.btnSave.Enabled = ((bool)(resources.GetObject("btnSave.Enabled")));
			this.btnSave.FlatStyle = ((System.Windows.Forms.FlatStyle)(resources.GetObject("btnSave.FlatStyle")));
			this.btnSave.Font = ((System.Drawing.Font)(resources.GetObject("btnSave.Font")));
			this.btnSave.Image = ((System.Drawing.Image)(resources.GetObject("btnSave.Image")));
			this.btnSave.ImageAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("btnSave.ImageAlign")));
			this.btnSave.ImageIndex = ((int)(resources.GetObject("btnSave.ImageIndex")));
			this.btnSave.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("btnSave.ImeMode")));
			this.btnSave.Location = ((System.Drawing.Point)(resources.GetObject("btnSave.Location")));
			this.btnSave.Name = "btnSave";
			this.btnSave.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("btnSave.RightToLeft")));
			this.btnSave.Size = ((System.Drawing.Size)(resources.GetObject("btnSave.Size")));
			this.btnSave.TabIndex = ((int)(resources.GetObject("btnSave.TabIndex")));
			this.btnSave.Text = resources.GetString("btnSave.Text");
			this.btnSave.TextAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("btnSave.TextAlign")));
			this.btnSave.Visible = ((bool)(resources.GetObject("btnSave.Visible")));
			this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
			// 
			// btnClose
			// 
			this.btnClose.AccessibleDescription = resources.GetString("btnClose.AccessibleDescription");
			this.btnClose.AccessibleName = resources.GetString("btnClose.AccessibleName");
			this.btnClose.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("btnClose.Anchor")));
			this.btnClose.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btnClose.BackgroundImage")));
			this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.btnClose.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("btnClose.Dock")));
			this.btnClose.Enabled = ((bool)(resources.GetObject("btnClose.Enabled")));
			this.btnClose.FlatStyle = ((System.Windows.Forms.FlatStyle)(resources.GetObject("btnClose.FlatStyle")));
			this.btnClose.Font = ((System.Drawing.Font)(resources.GetObject("btnClose.Font")));
			this.btnClose.Image = ((System.Drawing.Image)(resources.GetObject("btnClose.Image")));
			this.btnClose.ImageAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("btnClose.ImageAlign")));
			this.btnClose.ImageIndex = ((int)(resources.GetObject("btnClose.ImageIndex")));
			this.btnClose.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("btnClose.ImeMode")));
			this.btnClose.Location = ((System.Drawing.Point)(resources.GetObject("btnClose.Location")));
			this.btnClose.Name = "btnClose";
			this.btnClose.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("btnClose.RightToLeft")));
			this.btnClose.Size = ((System.Drawing.Size)(resources.GetObject("btnClose.Size")));
			this.btnClose.TabIndex = ((int)(resources.GetObject("btnClose.TabIndex")));
			this.btnClose.Text = resources.GetString("btnClose.Text");
			this.btnClose.TextAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("btnClose.TextAlign")));
			this.btnClose.Visible = ((bool)(resources.GetObject("btnClose.Visible")));
			this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
			// 
			// btnHelp
			// 
			this.btnHelp.AccessibleDescription = resources.GetString("btnHelp.AccessibleDescription");
			this.btnHelp.AccessibleName = resources.GetString("btnHelp.AccessibleName");
			this.btnHelp.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("btnHelp.Anchor")));
			this.btnHelp.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btnHelp.BackgroundImage")));
			this.btnHelp.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("btnHelp.Dock")));
			this.btnHelp.Enabled = ((bool)(resources.GetObject("btnHelp.Enabled")));
			this.btnHelp.FlatStyle = ((System.Windows.Forms.FlatStyle)(resources.GetObject("btnHelp.FlatStyle")));
			this.btnHelp.Font = ((System.Drawing.Font)(resources.GetObject("btnHelp.Font")));
			this.btnHelp.Image = ((System.Drawing.Image)(resources.GetObject("btnHelp.Image")));
			this.btnHelp.ImageAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("btnHelp.ImageAlign")));
			this.btnHelp.ImageIndex = ((int)(resources.GetObject("btnHelp.ImageIndex")));
			this.btnHelp.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("btnHelp.ImeMode")));
			this.btnHelp.Location = ((System.Drawing.Point)(resources.GetObject("btnHelp.Location")));
			this.btnHelp.Name = "btnHelp";
			this.btnHelp.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("btnHelp.RightToLeft")));
			this.btnHelp.Size = ((System.Drawing.Size)(resources.GetObject("btnHelp.Size")));
			this.btnHelp.TabIndex = ((int)(resources.GetObject("btnHelp.TabIndex")));
			this.btnHelp.Text = resources.GetString("btnHelp.Text");
			this.btnHelp.TextAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("btnHelp.TextAlign")));
			this.btnHelp.Visible = ((bool)(resources.GetObject("btnHelp.Visible")));
			// 
			// GrantRoleProtect
			// 
			this.AcceptButton = this.btnSave;
			this.AccessibleDescription = resources.GetString("$this.AccessibleDescription");
			this.AccessibleName = resources.GetString("$this.AccessibleName");
			this.AutoScaleBaseSize = ((System.Drawing.Size)(resources.GetObject("$this.AutoScaleBaseSize")));
			this.AutoScroll = ((bool)(resources.GetObject("$this.AutoScroll")));
			this.AutoScrollMargin = ((System.Drawing.Size)(resources.GetObject("$this.AutoScrollMargin")));
			this.AutoScrollMinSize = ((System.Drawing.Size)(resources.GetObject("$this.AutoScrollMinSize")));
			this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
			this.CancelButton = this.btnClose;
			this.ClientSize = ((System.Drawing.Size)(resources.GetObject("$this.ClientSize")));
			this.Controls.Add(this.btnSave);
			this.Controls.Add(this.btnClose);
			this.Controls.Add(this.pnlRoleProtection);
			this.Controls.Add(this.btnHelp);
			this.Enabled = ((bool)(resources.GetObject("$this.Enabled")));
			this.Font = ((System.Drawing.Font)(resources.GetObject("$this.Font")));
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("$this.ImeMode")));
			this.Location = ((System.Drawing.Point)(resources.GetObject("$this.Location")));
			this.MaximumSize = ((System.Drawing.Size)(resources.GetObject("$this.MaximumSize")));
			this.MinimumSize = ((System.Drawing.Size)(resources.GetObject("$this.MinimumSize")));
			this.Name = "GrantRoleProtect";
			this.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("$this.RightToLeft")));
			this.StartPosition = ((System.Windows.Forms.FormStartPosition)(resources.GetObject("$this.StartPosition")));
			this.Text = resources.GetString("$this.Text");
			this.Closing += new System.ComponentModel.CancelEventHandler(this.GrantRoleProtect_Closing);
			this.Load += new System.EventHandler(this.GrantRoleProtect_Load);
			this.pnlRoleProtection.ResumeLayout(false);
			this.grpProtection.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.c1FlexGridProtect)).EndInit();
			this.grpRole.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.c1FlexGridRole)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion		

		#region Class's Methods

		//**************************************************************************
		/// <summary>
		/// Load data from arrList into TreeProtect, This function 
		///	will build the tree, get data from collection arrStorePermission.
		///	RoleProtectionForm_Load and c1FlexGridRole_AfterRowColChange will call this function.
		/// </summary>
		/// <param name="c1FlexGridProtect"></param>
		/// <param name="pstrShortcut"></param>
		/// <param name="pintLevel"></param>
		/// <Author> Son HT, Dec 30, 2004</Author>
		private void LoadTreeProtect(ref C1FlexGrid c1FlexGridProtect,string pstrShortcut, int pintLevel)
		{
			for (int i = 0; i < arrSysMenuEntry.Count; i++)
			{
				Sys_Menu_EntryVO voMenu = (Sys_Menu_EntryVO) arrSysMenuEntry[i];
				// if this item is child node of current
				// as well as if it is a function with no form loaded or the formloaded is not right depended
				if ((voMenu.Parent_Shortcut.Equals(pstrShortcut)))// && (voMenu.Parent_Child != (int)MenuParentChildEnum.SpecialLeafMenu))
				{
					// Root Node
					intCurrentRow++;
					Node objNode = c1FlexGridProtect.Rows.InsertNode(intCurrentRow, pintLevel);
					string strLangName = CultureInfo.CurrentUICulture.Name;
					string strText = voMenu.Text_CaptionDefault;
					switch (strLangName)
					{
						case Constants.CULTURE_VN:
							strText = voMenu.Text_Caption_Vi_VN;
							break;
						case Constants.CULTURE_JP:
							strText = voMenu.Text_Caption_JA_JP;
							break;
						default:
							strText = voMenu.Text_CaptionDefault;
							break;
					}
					// Set Text for tree node
					c1FlexGridProtect[intCurrentRow, INT_POS_TREE] = strText;
					c1FlexGridProtect[intCurrentRow, INT_POS_MENU_ENTRY] = voMenu.Menu_EntryID;
					c1FlexGridProtect[intCurrentRow, INT_POS_PARENT_CHILD] = voMenu.Parent_Child;
					// If it is a leaf, then set checkbox otherwise don't set
					if (voMenu.Parent_Child == (int)MenuParentChildEnum.LeafMenu)
					{
						// Set check box for next cols
						c1FlexGridProtect.SetCellCheck(intCurrentRow,INT_POS_TREE,CheckEnum.Unchecked);
						// Set checking for column 'All'
						c1FlexGridProtect.SetCellCheck(intCurrentRow,INT_POS_ALL, CheckEnum.TSUnchecked);
						// Set checking for Columns
						c1FlexGridProtect.SetCellCheck(intCurrentRow,INT_POS_VIEW, CheckEnum.Unchecked);
						c1FlexGridProtect.SetCellCheck(intCurrentRow,INT_POS_ADD, CheckEnum.Unchecked);
						c1FlexGridProtect.SetCellCheck(intCurrentRow,INT_POS_EDIT, CheckEnum.Unchecked);
						c1FlexGridProtect.SetCellCheck(intCurrentRow,INT_POS_DELETE, CheckEnum.Unchecked);
						c1FlexGridProtect.SetCellCheck(intCurrentRow,INT_POS_PRINT, CheckEnum.Unchecked);
						
					}
					else
					{
						// Set TSUnchecked for column Tree
						c1FlexGridProtect.SetCellCheck(intCurrentRow,INT_POS_TREE,CheckEnum.TSUnchecked);
					}
					c1FlexGridProtect[intCurrentRow, INT_POS_PERMISSION] = 0;
					// Recursion build child node
					LoadTreeProtect(ref c1FlexGridProtect, voMenu.Shortcut, pintLevel+1);
					if (objNode.Level == 0)
					{
						objNode.Collapsed = true;
					}
				}
			}
		}		
		
		//**************************************************************************
		/// <summary>
		/// Load Role into List, get data from sys_Role table and load
		///	into c1FlexGridRole control. This function will be executed 
		///	only one time when the form is loaded.
		/// </summary>
		/// <Author> Son HT, Dec 30, 2004</Author>
		private void LoadRole()
		{
			string strLang = CultureInfo.CurrentUICulture.Name;
			switch (strLang)
			{
				case Constants.CULTURE_VN:
					NAME_COL = "Tên";
					DESC_COL = "Mô tả";
					break;
				case Constants.CULTURE_JP:
					NAME_COL = "Name (jp)";
					DESC_COL = "Description (jp)";
					break;
				default:
					NAME_COL = "Name";
					DESC_COL = "Description";
					break;
			}
			dstProtection.Tables[Sys_RoleTable.TABLE_NAME].Columns[1].ColumnName = NAME_COL;
			dstProtection.Tables[Sys_RoleTable.TABLE_NAME].Columns[2].ColumnName = DESC_COL;
			// Build the grid
			c1FlexGridRole.DataSource = dstProtection.Tables[Sys_RoleTable.TABLE_NAME];

			// Setting for First Column and First Row
			c1FlexGridRole.Cols[0].Width = c1FlexGridRole.Rows[0].HeightDisplay;
			// hidden RoleID column
			c1FlexGridRole.Cols[INT_START].Visible = false;
			c1FlexGridRole.Sort(SortFlags.Ascending,c1FlexGridRole.Cols[NAME_COL].Index);		
		}

		//**************************************************************************              		
		/// <summary>
		/// Set width column, column number, set styte for c1FlexGridProtect
		///	this function will be executed only one time when the form is loaded. 
		/// </summary>
		/// <Author> Son HT, Dec 30, 2004</Author>
		private void SetProtectFormat()
		{	
			// Set Tree column
			c1FlexGridProtect.Tree.Column = INT_POS_TREE;

			//Begin edit by duongna
			//Follow error 1994
			// Set width columns
			c1FlexGridProtect.Cols[0].Width = COLUMN_WIDTH_BASE;				
			c1FlexGridProtect.Cols[INT_POS_TREE].Width = COLUMN_WIDTH_BASE*10;
			//c1FlexGridProtect.Cols[INT_POS_ALL].Width = COLUMN_WIDTH_BASE;
			c1FlexGridProtect.Cols[INT_POS_VIEW].Width = COLUMN_WIDTH_BASE;
			c1FlexGridProtect.Cols[INT_POS_ADD].Width = COLUMN_WIDTH_BASE;
			c1FlexGridProtect.Cols[INT_POS_DELETE].Width = COLUMN_WIDTH_BASE;
			c1FlexGridProtect.Cols[INT_POS_PRINT].Width = COLUMN_WIDTH_BASE;
			//End edit by duongna

			// Center alignment
			c1FlexGridProtect.Cols[INT_POS_ALL].ImageAlign = 
				c1FlexGridProtect.Cols[INT_POS_VIEW].ImageAlign = 
				c1FlexGridProtect.Cols[INT_POS_ADD].ImageAlign = 
				c1FlexGridProtect.Cols[INT_POS_EDIT].ImageAlign = 
				c1FlexGridProtect.Cols[INT_POS_DELETE].ImageAlign = 
				c1FlexGridProtect.Cols[INT_POS_PRINT].ImageAlign = ImageAlignEnum.CenterCenter;		
		}
		
		//**************************************************************************
		/// <summary>
		/// Store all change of Role-Protection into sys_ProtectObj table.
		///	This function will be executed when user change selected row in 
		///	c1FlexGridRole or user click Close button on the form.
		/// </summary>
		/// <Author> Son HT, Dec 30, 2004</Author>
		private void StoreDatabase()
		{			
			CommonBO boCommon = new CommonBO();
			boCommon.UpdateRight(dstProtection);		
		}
		
		//**************************************************************************
		/// <summary>
		/// Store permission to dataset
		/// </summary>
		/// <param name="pvoSysRight"></param>
		/// <Author> Son HT, Dec 30, 2004</Author>
		private void StoreToDataSet(Sys_RightVO pvoSysRight)
		{
			// select a record from data table
			DataRow[] objRows = dstProtection.Tables[Sys_RightTable.TABLE_NAME].Select("(" + 
				Sys_RightTable.MENU_ENTRYID_FLD + "=" + pvoSysRight.Menu_EntryID.ToString() + ") AND (" +
				Sys_RightTable.ROLEID_FLD + "=" + pvoSysRight.RoleID.ToString() +")");
			// if 1 record is existed in database
			if (objRows.Length > 0)
			{
				objRows[0][Sys_RightTable.PERMISSION_FLD] = pvoSysRight.Permission;
			}
			else // add new record
			{
				DataRow objRow = dstProtection.Tables[Sys_RightTable.TABLE_NAME].NewRow();
				objRow[Sys_RightTable.MENU_ENTRYID_FLD] = pvoSysRight.Menu_EntryID;
				objRow[Sys_RightTable.ROLEID_FLD] = pvoSysRight.RoleID;
				objRow[Sys_RightTable.PERMISSION_FLD] = pvoSysRight.Permission;
				if(pvoSysRight.Permission > 0)
					dstProtection.Tables[Sys_RightTable.TABLE_NAME].Rows.Add(objRow);
			}
		}

		//**************************************************************************		
		/// <summary>
		/// Set checking for tree protection. This function wil be executed
		///	when user click on Protection tree column in c1FlexGridProtection
		///	(c1FlexGridProtect_Click will executed this function)
		/// </summary>
		/// <param name="pobjFlex">ref C1.Win.C1FlexGrid.C1FlexGrid objFlex</param>
		/// <param name="pintRow">the selected row.</param>
		/// <Author> Son HT, Dec 30, 2004</Author>
		private void CheckTreeColumn(ref C1FlexGrid pobjFlex,int pintRow)
		{
			// if Node of RowSel is Leaf node then Set properties for next columns
			if (int.Parse(c1FlexGridProtect.GetDataDisplay(pintRow, INT_POS_PARENT_CHILD).ToString()) == (int)MenuParentChildEnum.LeafMenu) 
			{
				int intOldPermission = int.Parse(c1FlexGridProtect.GetDataDisplay(pintRow,INT_POS_PERMISSION).ToString());
				// Setting checking for All column
				// if current node is Checked - Set Checked all column
				if(pobjFlex.GetCellCheck(pintRow,INT_POS_TREE) == CheckEnum.Checked)
				{
					pobjFlex.SetCellCheck(pintRow,INT_POS_ALL,CheckEnum.TSChecked);
					SetCheckedColumn(ref pobjFlex,pintRow);
					// Set Permission value
					pobjFlex.SetData(pintRow,INT_POS_PERMISSION,ACTION_ALL);
					//blnIsModified = true;
				}
					// if current node is Checked - Set Unchecked all column
				else if(pobjFlex.GetCellCheck(pintRow,INT_POS_TREE) == CheckEnum.Unchecked)
				{					
					// Set TSUnchecked for all col
					pobjFlex.SetCellCheck(pintRow,INT_POS_ALL,CheckEnum.TSUnchecked);
					SetUncheckedColumn(ref pobjFlex,pintRow);
					// Set Permission value
					pobjFlex.SetData(pintRow,INT_POS_PERMISSION,ACTION_NONE);
					//blnIsModified = true;
				}
				int intNewPermission = int.Parse(c1FlexGridProtect.GetDataDisplay(pintRow,INT_POS_PERMISSION).ToString());
				if(intNewPermission != intOldPermission) blnIsModified = true;
				// if current node is TSChecked - Checked all child node
				Node objNode = pobjFlex.Rows[pintRow].Node;						
				// Set checking for parent node
				SetCheckForParent(ref pobjFlex,ref objNode);
			}
				// Set properties for Parent Node or Root and Special node on the Tree
			else
			{
				int intOldPermission = int.Parse(c1FlexGridProtect.GetDataDisplay(pintRow,INT_POS_PERMISSION).ToString());
				if((pobjFlex.GetCellCheck(pintRow,INT_POS_TREE) == CheckEnum.TSGrayed) 
					|| (pobjFlex.GetCellCheck(pintRow,INT_POS_TREE) == CheckEnum.TSChecked))
				{
					pobjFlex.SetCellCheck(pintRow,INT_POS_TREE,CheckEnum.TSChecked);
					c1FlexGridProtect.SetData(pintRow,INT_POS_PERMISSION,ACTION_VIEW);
				}
				else if(pobjFlex.GetCellCheck(pintRow,INT_POS_TREE) == CheckEnum.TSUnchecked) 
				{
					c1FlexGridProtect.SetData(pintRow,INT_POS_PERMISSION,ACTION_NONE);
				}
				// with node has no children
				if(pobjFlex.GetCellCheck(pintRow,INT_POS_TREE) == CheckEnum.Checked)
				{
					c1FlexGridProtect.SetData(pintRow,INT_POS_PERMISSION,ACTION_VIEW);
				}
				else if(pobjFlex.GetCellCheck(pintRow,INT_POS_TREE) == CheckEnum.Unchecked)
				{
					c1FlexGridProtect.SetData(pintRow,INT_POS_PERMISSION,ACTION_NONE);
				}
				int intNewPermission = int.Parse(c1FlexGridProtect.GetDataDisplay(pintRow,INT_POS_PERMISSION).ToString());
				if(intNewPermission != intOldPermission) blnIsModified = true;
				// if current node is TSChecked - Checked all child node
				Node objNode = pobjFlex.Rows[pintRow].Node;						
				// Set checking for parent node
				SetCheckForParent(ref pobjFlex,ref objNode);
				if((int.Parse(c1FlexGridProtect.GetDataDisplay(pintRow,INT_POS_PARENT_CHILD).ToString()) == (int)MenuParentChildEnum.RootMenu) || 
					(int.Parse(c1FlexGridProtect.GetDataDisplay(pintRow,INT_POS_PARENT_CHILD).ToString()) == (int)MenuParentChildEnum.NormalMenu))
				{
					// Set Checked for all child node 
					//CheckEnum chk = pobjFlex.GetCellCheck(pintRow,INT_POS_TREE);
					//if (chk == CheckEnum.TSUnchecked)
					//{
					SetCheckForChild(ref pobjFlex,ref objNode);
					//}
				}
			}		
		}
		
		//**************************************************************************		
		/// <summary>
		/// Set checking for child node when user click a parent node on the tree.
		///	This function set all child node is checked,unchecked,TSGrayed, TSChecked or TSUnchecked.
		///	This function will be execute by CheckTreeColumn function
		/// </summary>
		/// <param name="objFlex">pointer to c1FlexGridProtection control</param>
		/// <param name="pNode">current seleted node (user click on this node)</param>
		/// <Author> Son HT, Dec 30, 2004 </Author>
		private void SetCheckForChild(ref C1FlexGrid objFlex,ref Node pNode)
		{
			Node objFirstChild = pNode.GetNode(NodeTypeEnum.FirstChild);
			// Get check enum of current node
			CheckEnum chkParentEnum = objFlex.GetCellCheck(pNode.Row.Index,INT_POS_TREE);			
			while(objFirstChild != null)
			{
				CheckEnum chkEnum = chkParentEnum;
				if (chkParentEnum != CheckEnum.TSGrayed) 
				{
					// if child is not a leaf node
					bool blnUnchecked = (objFlex.GetCellCheck(objFirstChild.Row.Index,INT_POS_TREE) == CheckEnum.Unchecked);
					bool blnChecked = (objFlex.GetCellCheck(objFirstChild.Row.Index,INT_POS_TREE) == CheckEnum.Checked);
					if((blnUnchecked) || (blnChecked))
					{
						if(chkParentEnum == CheckEnum.TSChecked) chkEnum = CheckEnum.Checked;
						else chkEnum = CheckEnum.Unchecked;
					}
					// Set check for child
					objFlex.SetCellCheck(objFirstChild.Row.Index,INT_POS_TREE,chkEnum);
					if(objFlex.GetCellCheck(objFirstChild.Row.Index,INT_POS_TREE) == CheckEnum.TSUnchecked)
					{
						objFlex.SetData(objFirstChild.Row.Index,INT_POS_PERMISSION,ACTION_NONE);
					}
					else
					{
						objFlex.SetData(objFirstChild.Row.Index,INT_POS_PERMISSION,ACTION_VIEW);
					}
					// Set check for all columns
					if (chkEnum == CheckEnum.Checked)
					{							
						// if objFirstChild is leaf
						if(int.Parse(objFlex.GetData(objFirstChild.Row.Index,INT_POS_PARENT_CHILD).ToString()) ==  (int)MenuParentChildEnum.LeafMenu)
						{
							SetCheckedColumn(ref objFlex,objFirstChild.Row.Index);
							objFlex.SetCellCheck(objFirstChild.Row.Index,INT_POS_ALL,CheckEnum.Checked);	
							c1FlexGridProtect.SetData(objFirstChild.Row.Index,INT_POS_PERMISSION,ACTION_ALL);
							blnIsModified = true;
						}
					}
					else if (chkEnum == CheckEnum.Unchecked)
					{
						if(int.Parse(objFlex.GetData(objFirstChild.Row.Index,INT_POS_PARENT_CHILD).ToString()) ==  (int)MenuParentChildEnum.LeafMenu)
						{
							SetUncheckedColumn(ref objFlex,objFirstChild.Row.Index);
							objFlex.SetCellCheck(objFirstChild.Row.Index,INT_POS_ALL,CheckEnum.TSUnchecked);
							c1FlexGridProtect.SetData(objFirstChild.Row.Index,INT_POS_PERMISSION,ACTION_NONE);
							blnIsModified = true;
						}
					}
					// Rescursion
					SetCheckForChild(ref objFlex,ref objFirstChild);
				}
				objFirstChild = objFirstChild.GetNode(NodeTypeEnum.NextSibling);
			}		
		}

		
		//**************************************************************************		
		/// <summary>
		/// Set checking for parent node when user click a child node on the tree.
		///	This function set all parent node of pNode(selected node) to be Checked,Unchecked,...
		///	This function will be executed by CheckTreeColumn function
		/// </summary>
		/// <param name="pobjFlex">pointer to c1FlexGridProtection control</param>
		/// <param name="pobjNode">current seleted node (user click on this node)</param>
		/// <Author> Son HT, Dec 30, 2004</Author>
		
		private void SetCheckForParent(ref C1FlexGrid pobjFlex,ref Node pobjNode)
		{
			const string METHOD_NAME = THIS + ".SetCheckForParent()";
			// if current node is first node
			Node objFirst = pobjNode.GetNode(NodeTypeEnum.FirstSibling);	// Get first child node
			// if user click on firstsibling node
			if(objFirst == null) objFirst = pobjNode;
			// Get parent node
			Node objParent = pobjNode.GetNode(NodeTypeEnum.Parent);
			bool blnIsChecked = true;
			bool blnIsUnchecked = true;
			// Scan all node on the tree
			while(objFirst != null)
			{
				// get condition
				bool blnTSUnchecked = (pobjFlex.GetCellCheck( objFirst.Row.Index,INT_POS_TREE) == CheckEnum.TSUnchecked );
				bool blnUnchecked = (pobjFlex.GetCellCheck( objFirst.Row.Index,INT_POS_TREE) == CheckEnum.Unchecked );
				bool blnTSChecked = (pobjFlex.GetCellCheck( objFirst.Row.Index,INT_POS_TREE) == CheckEnum.TSChecked );
				bool blnTSGrayed = (pobjFlex.GetCellCheck( objFirst.Row.Index,INT_POS_TREE) == CheckEnum.TSGrayed);
				bool blnChecked = (pobjFlex.GetCellCheck( objFirst.Row.Index,INT_POS_TREE) == CheckEnum.Checked );
				// if exit a node uncheck, set blnCheck = false 
				if((blnTSUnchecked) || (blnTSGrayed) || (blnUnchecked))
				{
					blnIsChecked = false;
				}
				// if exit a node checked, set blnUncheck = false 
				if((blnTSChecked) || (blnTSGrayed) || (blnChecked))
				{
					blnIsUnchecked = false;
				}	
				// Move to next node
				objFirst = objFirst.GetNode(NodeTypeEnum.NextSibling);
			}
			// Setting for parent node
			if(objParent != null)
			{
				// if all child item is checked
				if(blnIsChecked)
				{
					// Set checked for parent
					pobjFlex.SetCellCheck(objParent.Row.Index,INT_POS_TREE,CheckEnum.TSChecked);
					pobjFlex.SetData(objParent.Row.Index,INT_POS_PERMISSION,ACTION_VIEW);
				}
				else if(blnIsUnchecked) // if all child item is unchecked
				{
					// Set Unchecked for parent
					pobjFlex.SetCellCheck(objParent.Row.Index,INT_POS_TREE,CheckEnum.TSUnchecked);
					pobjFlex.SetData(objParent.Row.Index,INT_POS_PERMISSION,ACTION_NONE);
				}
				else // if some child item is checked and some is unchecked 
				{
					// Set TSGrayed for parent
					pobjFlex.SetCellCheck(objParent.Row.Index,INT_POS_TREE,CheckEnum.TSGrayed);
					pobjFlex.SetData(objParent.Row.Index,INT_POS_PERMISSION,ACTION_VIEW);
				}
				// rescursion
				SetCheckForParent(ref pobjFlex,ref objParent);
			}	
		}		           
		
		//**************************************************************************
		/// <summary>
		/// Set checking for the column All. When user click on the column All.
		///	All properties will be setted, and the checkbox in the tree is setted too.
		///	This function will be execute when user click on the c1FlexGridProtection control
		/// </summary>
		/// <param name="pobjFlex"> </param>
		/// <param name="pintRow"> </param>
		/// <Author> Son HT, Dec 30, 2004</Author>
		private void CheckAllColumn(ref C1FlexGrid pobjFlex, int pintRow)
		{
			// Select Checked all
			if((pobjFlex.GetCellCheck(pintRow,INT_POS_ALL) == CheckEnum.TSChecked) ||
				(pobjFlex.GetCellCheck(pintRow,INT_POS_ALL) == CheckEnum.TSGrayed))
			{
				if (pobjFlex.GetCellCheck(pintRow,INT_POS_ALL) == CheckEnum.TSGrayed)
					pobjFlex.SetCellCheck(pintRow,INT_POS_ALL,CheckEnum.TSChecked);
				pobjFlex.SetCellCheck(pintRow,INT_POS_TREE,CheckEnum.Checked);
				SetCheckedColumn(ref pobjFlex,pintRow);
				c1FlexGridProtect.SetData(pintRow,INT_POS_PERMISSION,ACTION_ALL);
				blnIsModified = true;
			}
				// Select UnChecked all
			else if(pobjFlex.GetCellCheck(pintRow,INT_POS_ALL) == CheckEnum.TSUnchecked)
			{
				pobjFlex.SetCellCheck(pintRow,INT_POS_TREE,CheckEnum.Unchecked);
				SetUncheckedColumn(ref pobjFlex,pintRow);
				c1FlexGridProtect.SetData(pintRow,INT_POS_PERMISSION,ACTION_NONE);
				blnIsModified = true;
			}
			// Set checking for parent node
			Node objNode = pobjFlex.Rows[pintRow].Node;
			SetCheckForParent(ref pobjFlex,ref objNode);	
		}		
		
		//**************************************************************************
		/// <summary>
		/// Set checking for all columns in grid and set permission for object
		/// </summary>
		/// <param name="pobjFlex"></param>
		/// <param name="pintRow"></param>
		/// <Author> Son HT, Dec 30, 2004</Author>
		private void CheckPropertiesColumn(ref C1FlexGrid pobjFlex,int pintRow)
		{
			// Get action of user, assign action to intAction variable
			int intAction = 0;		// get Action value
			if(pobjFlex.ColSel == INT_POS_VIEW) intAction = ACTION_VIEW;
			else if (pobjFlex.ColSel == INT_POS_ADD) intAction = ACTION_ADD;
			else if (pobjFlex.ColSel == INT_POS_EDIT) intAction = ACTION_EDIT;
			else if (pobjFlex.ColSel == INT_POS_DELETE) intAction = ACTION_DELETE;
			else if (pobjFlex.ColSel == INT_POS_PRINT) intAction = ACTION_PRINT;
				
			// if selected cell change from Unchecked to Checked then add permission on this item
			if(pobjFlex.GetCellCheck(pintRow,pobjFlex.ColSel) == CheckEnum.Checked)
			{
				int intPermission = int.Parse(c1FlexGridProtect.GetDataDisplay(pintRow,INT_POS_PERMISSION).ToString());
				// If the object has had an Action in permission then add right to permission
				if((intPermission & intAction) != intAction)
				{
					// Add action when user change from Uncheck -> Check
					intPermission = intPermission + intAction;
					c1FlexGridProtect.SetData(pintRow,INT_POS_PERMISSION,intPermission);
					blnIsModified = true;
				}
				// auto set checked for View column
				if((intPermission & ACTION_VIEW) != ACTION_VIEW)
				{
					// Add action when user change from Uncheck -> Check
					intPermission = intPermission + ACTION_VIEW;
					c1FlexGridProtect.SetData(pintRow,INT_POS_PERMISSION,intPermission);
					c1FlexGridProtect.SetCellCheck(pintRow,INT_POS_VIEW,CheckEnum.Checked);
					blnIsModified = true;
				}
			}
				// if current cell change from Checked to Unchecked then move permission
			else if(pobjFlex.GetCellCheck(pintRow,pobjFlex.ColSel) == CheckEnum.Unchecked)
			{
				// Remove action when user change from Check -> Uncheck
				int intPermission = int.Parse(c1FlexGridProtect.GetDataDisplay(pintRow,INT_POS_PERMISSION).ToString());

				// if column View change from Checked -> Uncheck and other column still checked then warning message
				if((pobjFlex.ColSel == INT_POS_VIEW) && (intPermission > ACTION_VIEW) && ((intPermission & ACTION_VIEW) == ACTION_VIEW))
				{
					// Warning: You must set uncheck for all other columns before set uncheck for this column
					PCSMessageBox.Show(ErrorCode.MESSAGE_UNCHECK_OTHER_COLUMNS_BEFORE_VIEW,MessageBoxIcon.Warning);
					pobjFlex.SetCellCheck(pintRow,pobjFlex.ColSel,CheckEnum.Checked);
					return;
				}

				if((intPermission & intAction) == intAction)
				{
					// Add action when user change from Uncheck -> Check
					intPermission = intPermission - intAction;
					c1FlexGridProtect.SetData(pintRow,INT_POS_PERMISSION,intPermission);
					blnIsModified = true;
				}
			}

			// Set TSChecked for column All 
			if(int.Parse(c1FlexGridProtect.GetDataDisplay(pintRow,INT_POS_PERMISSION).ToString()) == ACTION_ALL)
			{
				pobjFlex.SetCellCheck(pintRow,INT_POS_ALL,CheckEnum.TSChecked);
			}
				// Set Unchecked
			else if(int.Parse(c1FlexGridProtect.GetDataDisplay(pintRow,INT_POS_PERMISSION).ToString()) == ACTION_NONE)
			{
				pobjFlex.SetCellCheck(pintRow,INT_POS_ALL,CheckEnum.TSUnchecked);
			}
				// Set Grayed
			else
			{
				pobjFlex.SetCellCheck(pintRow,INT_POS_ALL,CheckEnum.TSGrayed);
			}
			// Set Checking for column Tree 
			if(int.Parse(c1FlexGridProtect.GetDataDisplay(pintRow,INT_POS_PERMISSION).ToString()) == ACTION_NONE)
			{
				pobjFlex.SetCellCheck(pintRow,INT_POS_TREE,CheckEnum.Unchecked);
			}
			else
			{
				pobjFlex.SetCellCheck(pintRow,INT_POS_TREE,CheckEnum.Checked);
			}
			// Set current status checkbox
			Node objNode = pobjFlex.Rows[pintRow].Node;
			SetCheckForParent(ref pobjFlex,ref objNode);	
		}
		
		//**************************************************************************
		/// <summary>
		/// Set Unchecked for properties column, this function set all properties
		///	column is Unchecked, more function call this fucntion, it's help us 
		///	easy to read the code.
		/// </summary>
		/// <param name="pobjFlex"></param>
		/// <param name="pintRow"></param>
		/// <Author> Son HT, Dec 30, 2004</Author>
		private void SetUncheckedColumn(ref C1FlexGrid pobjFlex,int pintRow)
		{
			pobjFlex.SetCellCheck(pintRow,INT_POS_VIEW,CheckEnum.Unchecked);
			pobjFlex.SetCellCheck(pintRow,INT_POS_ADD,CheckEnum.Unchecked);
			pobjFlex.SetCellCheck(pintRow,INT_POS_EDIT,CheckEnum.Unchecked);
			pobjFlex.SetCellCheck(pintRow,INT_POS_DELETE,CheckEnum.Unchecked);			
			pobjFlex.SetCellCheck(pintRow,INT_POS_PRINT,CheckEnum.Unchecked);			
		}

		//**************************************************************************		
		/// <summary>
		/// Set checked for properties column, this function set all properties
		///	column is checked, more function call this fucntion, it's help us 
		///	easy to read the code.
		/// </summary>
		/// <param name="pobjFlex"></param>
		/// <param name="pintRow"></param>
		/// <Author> Son HT, Dec 30, 2004</Author>
		private void SetCheckedColumn(ref C1FlexGrid pobjFlex,int pintRow)
		{			
			pobjFlex.SetCellCheck(pintRow,INT_POS_VIEW,CheckEnum.Checked);
			pobjFlex.SetCellCheck(pintRow,INT_POS_ADD,CheckEnum.Checked);
			pobjFlex.SetCellCheck(pintRow,INT_POS_EDIT,CheckEnum.Checked);
			pobjFlex.SetCellCheck(pintRow,INT_POS_DELETE,CheckEnum.Checked);			
			pobjFlex.SetCellCheck(pintRow,INT_POS_PRINT,CheckEnum.Checked);			
		}
		
		//**************************************************************************
		/// <summary>
		/// This method uses to Store data
		/// </summary>
		/// <Author> Son HT, Jan 20, 2005</Author>
		private void CleanAndStore()
		{
			for(int i = INT_START; i < c1FlexGridProtect.Rows.Count; i++)
			{
				// is leaf
				if (int.Parse(c1FlexGridProtect.GetDataDisplay(i,INT_POS_PARENT_CHILD).ToString()) == (int)MenuParentChildEnum.LeafMenu) 
				{
					// Store to dataset
					Sys_RightVO voSysRight = new Sys_RightVO();
					voSysRight.Menu_EntryID = int.Parse(c1FlexGridProtect.GetDataDisplay(i,INT_POS_MENU_ENTRY).ToString());
					voSysRight.RoleID = int.Parse(c1FlexGridRole.GetDataDisplay(c1FlexGridRole.RowSel,INT_START).ToString());
					voSysRight.Permission = int.Parse(c1FlexGridProtect.GetDataDisplay(i,INT_POS_PERMISSION).ToString());
					StoreToDataSet(voSysRight);
					SetUncheckedColumn(ref c1FlexGridProtect,i);
					c1FlexGridProtect.SetCellCheck(i,INT_POS_ALL,CheckEnum.TSUnchecked);
					c1FlexGridProtect.SetCellCheck(i,INT_POS_TREE,CheckEnum.Unchecked);
					c1FlexGridProtect[i, INT_POS_PERMISSION] = ACTION_NONE;
				}
				else
				{
					// Store to dataset
					Sys_RightVO voSysRight = new Sys_RightVO();
					voSysRight.Menu_EntryID = int.Parse(c1FlexGridProtect.GetDataDisplay(i,INT_POS_MENU_ENTRY).ToString());
					voSysRight.RoleID = int.Parse(c1FlexGridRole.GetDataDisplay(c1FlexGridRole.RowSel,INT_START).ToString());
					voSysRight.Permission = int.Parse(c1FlexGridProtect.GetDataDisplay(i,INT_POS_PERMISSION).ToString());
					StoreToDataSet(voSysRight);
					c1FlexGridProtect.SetCellCheck(i,INT_POS_TREE,CheckEnum.TSUnchecked);
					c1FlexGridProtect[i, INT_POS_PERMISSION] = ACTION_NONE;
				}
			}
		}
		
		//**************************************************************************		
		/// <summary>
		/// This method uses to 
		/// </summary>
		/// <param name="pintRoleID">Role ID</param>
		/// <Author> Son HT, Dec 30, 2004</Author>
		private void LoadCheckingOfProtect(int pintRoleID)
		{
			//for(int intRow = 0; intRow < arrList.Count; intRow++)
			int intRow = 1;
			string strMenu_EntryID = string.Empty;
			if(intRow < c1FlexGridProtect.Rows.Count)
				strMenu_EntryID = c1FlexGridProtect.GetDataDisplay(intRow,INT_POS_MENU_ENTRY).Trim();
			int intPermission = 0;
			// Scan all row in protected object
			while(strMenu_EntryID != string.Empty)
			{
				// set checked for leaf
				if(int.Parse(c1FlexGridProtect.GetDataDisplay(intRow,INT_POS_PARENT_CHILD)) == (int)MenuParentChildEnum.LeafMenu)
				{
					DataRow[] objRows = dstProtection.Tables[Sys_RightTable.TABLE_NAME].Select("(" + Sys_RightTable.MENU_ENTRYID_FLD + "="
						+ strMenu_EntryID + ") AND (" +Sys_RightTable.ROLEID_FLD + "=" + pintRoleID.ToString() + ")");
					if(objRows.Length > 0)
					{
						if(objRows[0][Sys_RightTable.PERMISSION_FLD].ToString().Length > 0)
							intPermission = int.Parse(objRows[0][Sys_RightTable.PERMISSION_FLD].ToString()) ;
						// Set Permission for leaf
						if(intPermission > ACTION_NONE)
							c1FlexGridProtect.SetCellCheck(intRow,INT_POS_TREE,CheckEnum.Checked);
						else
							c1FlexGridProtect.SetCellCheck(intRow,INT_POS_TREE,CheckEnum.Unchecked);
						// Column 'All'
						if(intPermission == ACTION_ALL)
							c1FlexGridProtect.SetCellCheck(intRow,INT_POS_ALL,CheckEnum.TSChecked);
						else if(intPermission == ACTION_NONE)
							c1FlexGridProtect.SetCellCheck(intRow,INT_POS_ALL,CheckEnum.TSUnchecked);
						else c1FlexGridProtect.SetCellCheck(intRow,INT_POS_ALL,CheckEnum.TSGrayed);
						// other Columns 
						c1FlexGridProtect.SetCellCheck(intRow,INT_POS_VIEW,
							((intPermission & ACTION_VIEW)==ACTION_VIEW ? CheckEnum.Checked: CheckEnum.Unchecked));
						c1FlexGridProtect.SetCellCheck(intRow,INT_POS_ADD,
							((intPermission & ACTION_ADD)==ACTION_ADD ? CheckEnum.Checked: CheckEnum.Unchecked));
						c1FlexGridProtect.SetCellCheck(intRow,INT_POS_EDIT,
							((intPermission & ACTION_EDIT)==ACTION_EDIT ? CheckEnum.Checked: CheckEnum.Unchecked));
						c1FlexGridProtect.SetCellCheck(intRow,INT_POS_DELETE,
							((intPermission & ACTION_DELETE)==ACTION_DELETE ? CheckEnum.Checked: CheckEnum.Unchecked));
						c1FlexGridProtect.SetCellCheck(intRow,INT_POS_PRINT,
							((intPermission & ACTION_PRINT)==ACTION_PRINT ? CheckEnum.Checked: CheckEnum.Unchecked));
						c1FlexGridProtect.SetData(intRow,INT_POS_PERMISSION,intPermission);
						
						// Set checking for parent node
						Node objNode = c1FlexGridProtect.Rows[intRow].Node; 
						//if(objNode.GetNode(NodeTypeEnum.NextSibling) == null)
						SetCheckForParent(ref c1FlexGridProtect,ref objNode);
					}
				}
				else // set permission for parent or root
				{
					DataRow[] objRows = dstProtection.Tables[Sys_RightTable.TABLE_NAME].Select("(" + Sys_RightTable.MENU_ENTRYID_FLD + "="
						+ strMenu_EntryID + ") AND (" +Sys_RightTable.ROLEID_FLD + "=" + pintRoleID.ToString() + ")");
					if(objRows.Length > 0)
					{
						if(objRows[0][Sys_RightTable.PERMISSION_FLD].ToString().Length > 0)
							intPermission = int.Parse(objRows[0][Sys_RightTable.PERMISSION_FLD].ToString()) ;
						c1FlexGridProtect.SetData(intRow,INT_POS_PERMISSION,intPermission);
						// Set Permission for parent
						if(int.Parse(c1FlexGridProtect.GetDataDisplay(intRow,INT_POS_PARENT_CHILD)) != (int)MenuParentChildEnum.LeafMenu)
							if(intPermission > ACTION_NONE)
								c1FlexGridProtect.SetCellCheck(intRow,INT_POS_TREE,CheckEnum.Checked);
							else
								c1FlexGridProtect.SetCellCheck(intRow,INT_POS_TREE,CheckEnum.Unchecked);

						// Set checking for parent node
						Node objNode = c1FlexGridProtect.Rows[intRow].Node; 
						//if(objNode.GetNode(NodeTypeEnum.NextSibling) == null)
						SetCheckForParent(ref c1FlexGridProtect,ref objNode);
					}
				}

				// next row in grid function
				intRow++;
				if(intRow < c1FlexGridProtect.Rows.Count)
					strMenu_EntryID = c1FlexGridProtect.GetDataDisplay(intRow,INT_POS_MENU_ENTRY).Trim();
				else strMenu_EntryID = string.Empty;
			}		
		}

		//**************************************************************************		
		/// <summary>
		/// This method uses to 
		/// </summary>
		/// <param name="pstrTableName"> Table name</param>
		/// <returns></returns>
		/// <Author> Son HT, Dec 30, 2004</Author>
		private ArrayList TableToArray(string pstrTableName)
		{
			const string METHOD_NAME = THIS + ".TableToArray()";
			ArrayList arrObject = new ArrayList();
			if(pstrTableName.Equals(Sys_Menu_EntryTable.TABLE_NAME))
			{
				foreach (DataRow objRow in dstProtection.Tables[pstrTableName].Rows)
				{
					Sys_Menu_EntryVO voMenu = new Sys_Menu_EntryVO();
					voMenu.Parent_Shortcut = objRow[Sys_Menu_EntryTable.PARENT_SHORTCUT_FLD].ToString().Trim();
					voMenu.Menu_EntryID = int.Parse(objRow[Sys_Menu_EntryTable.MENU_ENTRYID_FLD].ToString());
					voMenu.Shortcut = objRow[Sys_Menu_EntryTable.SHORTCUT_FLD].ToString().Trim();
					voMenu.Button_Caption = int.Parse(objRow[Sys_Menu_EntryTable.BUTTON_CAPTION_FLD].ToString());
					voMenu.Text_CaptionDefault = objRow[Sys_Menu_EntryTable.TEXT_CAPTIONDEFAULT_FLD].ToString().Trim();
					voMenu.Text_Caption_Vi_VN = objRow[Sys_Menu_EntryTable.TEXT_CAPTION_VI_VN_FLD].ToString().Trim();
					voMenu.Text_Caption_EN_US = objRow[Sys_Menu_EntryTable.TEXT_CAPTION_EN_US_FLD].ToString().Trim();
					voMenu.Text_Caption_JA_JP = objRow[Sys_Menu_EntryTable.TEXT_CAPTION_JA_JP_FLD].ToString().Trim();
					voMenu.Text_Caption_Language_Default = objRow[Sys_Menu_EntryTable.TEXT_CAPTION_LANGUAGE_DEFAULT_FLD].ToString().Trim();
					voMenu.Parent_Child = int.Parse(objRow[Sys_Menu_EntryTable.PARENT_CHILD_FLD].ToString());
					voMenu.FormLoad = objRow[Sys_Menu_EntryTable.FORMLOAD_FLD].ToString().Trim();
					voMenu.Type = int.Parse(objRow[Sys_Menu_EntryTable.TYPE_FLD].ToString());
					arrObject.Add(voMenu);
				}
			}
			return arrObject;
		}

		#endregion

		#region Event Processing

		//**************************************************************************
		/// <summary>
		/// 
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		/// <Author> Son HT, Dec 30, 2004</Author>
		private void GrantRoleProtect_Load(object sender, EventArgs e)
		{
			// Code Inserted Automatically

			#region Code Inserted Automatically

			this.Cursor = Cursors.WaitCursor;

			#endregion Code Inserted Automatically

			
			const string METHOD_NAME = THIS + ".GrantRoleProtect_Load()";
			const string MAIN = "MAIN";
			try
			{
				#region Security
				//Set authorization for user
				Security objSecurity = new Security();
				this.Name = THIS;
				if(objSecurity.SetRightForUserOnForm(this, SystemProperty.UserName) == 0)
				{
					this.Close();
					// You don't have the right to view this item
					PCSMessageBox.Show(ErrorCode.MESSAGE_YOU_HAVE_NO_RIGHT_TO_VIEW ,MessageBoxIcon.Warning);
					// Code Inserted Automatically
					#region Code Inserted Automatically
					this.Cursor = Cursors.Default;
					#endregion Code Inserted Automatically

					return;
				}
				#endregion
				
				// Load data from database
				CommonBO boCommon = new CommonBO();
				dstProtection = boCommon.GetAllProtection();
				dstProtection.Tables[Sys_RightTable.TABLE_NAME].Columns[Sys_RightTable.RIGHTID_FLD].AutoIncrement = true;
				// Load Role GridFlex table
				if(dstProtection.Tables[Sys_RoleTable.TABLE_NAME].Rows.Count > 0)
					LoadRole();
				else 
					return;
				// fill array from table
				arrSysMenuEntry = TableToArray(Sys_Menu_EntryTable.TABLE_NAME);
				// Set visible columns
				c1FlexGridProtect.Cols[INT_POS_MENU_ENTRY].Visible = false;
				c1FlexGridProtect.Cols[INT_POS_PARENT_CHILD].Visible = false;
				c1FlexGridProtect.Cols[INT_POS_PERMISSION].Visible = false;

				//Begin edit by duongna 11-10-2005
				//Follow error 1994
				c1FlexGridProtect.Cols[INT_POS_ALL].Visible = false;
				c1FlexGridProtect.Cols[INT_POS_VIEW].Visible = false;
				c1FlexGridProtect.Cols[INT_POS_ADD].Visible = false;
				c1FlexGridProtect.Cols[INT_POS_EDIT].Visible = false;
				c1FlexGridProtect.Cols[INT_POS_DELETE].Visible = false;
				c1FlexGridProtect.Cols[INT_POS_PRINT].Visible = false;
				//End edit by duongna 11-10-2005

				// Set table Protect format
				SetProtectFormat();
				// Current row that system create row when Load tree data
				intCurrentRow = 0;
				LoadTreeProtect(ref this.c1FlexGridProtect, MAIN, intCurrentRow);
				// load checking of tree
				if (c1FlexGridRole.Rows.Count > 0)
					LoadCheckingOfProtect(int.Parse(c1FlexGridRole.GetDataDisplay(INT_START,INT_START).ToString()));
				//set start col outside of tree col
				c1FlexGridProtect.Col = INT_POS_PRINT + 1;
			}
			catch (PCSException ex)
			{
				// displays the error message.
				PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
				// log message.
				try
				{
					Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
				}
				catch
				{
					PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
				}
			}
			catch (Exception ex)
			{
				// displays the error message.
				PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
				// log message.
				try
				{
					Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
				}
				catch
				{
					PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
				}			
			}		

			// Code Inserted Automatically

			#region Code Inserted Automatically

			this.Cursor = Cursors.Default;

			#endregion Code Inserted Automatically

			
		}
		
		//**************************************************************************
		/// <summary>
		/// 
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		/// <Author> Son HT, Dec 30, 2004</Author>
		private void c1FlexGridProtect_Click(object sender, EventArgs e)
		{
			// Code Inserted Automatically

			#region Code Inserted Automatically

			this.Cursor = Cursors.WaitCursor;

			#endregion Code Inserted Automatically

			
			// Get C1FlexGrid object
			C1FlexGrid objC1FlexGrid = (C1FlexGrid)sender;
			// Check row in range
			if(objC1FlexGrid.RowSel > 0)
			{
				// Check Tree columns 
				if(objC1FlexGrid.ColSel == INT_POS_TREE)
				{
					CheckTreeColumn(ref objC1FlexGrid, objC1FlexGrid.RowSel);
				}

				// If user clicks on checkbox of Leaf
				if (int.Parse(c1FlexGridProtect.GetDataDisplay(objC1FlexGrid.RowSel,INT_POS_PARENT_CHILD).ToString()) == (int)MenuParentChildEnum.LeafMenu) 
				{
					// if user click on All column
					if(objC1FlexGrid.ColSel == INT_POS_ALL)
					{
						// Set checking for All column
						CheckAllColumn(ref objC1FlexGrid, objC1FlexGrid.RowSel);
					}
						// if user click on other columns
					else
					{
						if(objC1FlexGrid.ColSel > INT_POS_ALL)
						{
							// Set checking for Read|Write|Execute|Delete
							CheckPropertiesColumn(ref objC1FlexGrid, objC1FlexGrid.RowSel);
						}
					}
				}
			}

			// Code Inserted Automatically

			#region Code Inserted Automatically

			this.Cursor = Cursors.Default;

			#endregion Code Inserted Automatically

			
		}
		
		//**************************************************************************
		/// <summary>
		/// 
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		/// <Author> Son HT, Dec 30, 2004</Author>
		private void btnClose_Click(object sender, EventArgs e)
		{
			// Code Inserted Automatically

			#region Code Inserted Automatically

			this.Cursor = Cursors.WaitCursor;

			#endregion Code Inserted Automatically

			
			this.Close();

			// Code Inserted Automatically

			#region Code Inserted Automatically

			this.Cursor = Cursors.Default;

			#endregion Code Inserted Automatically

			
		}
		
		//**************************************************************************
		/// <summary>
		/// 
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		/// <Author> Son HT, Dec 30, 2004</Author>
		private void c1FlexGridRole_BeforeRowColChange(object sender, RangeEventArgs e)
		{	
			const string METHOD_NAME = THIS + ".c1FlexGridRole_BeforeRowColChange()";
			try
			{
				// if user move to an other row
				if(e.OldRange.r1 != e.NewRange.r1)
				{
					// Clear checked and store permission to dataset
					CleanAndStore();
				}
			}
			catch (PCSException ex)
			{
				// displays the error message.
				PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
				// log message.
				try
				{
					Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
				}
				catch
				{
					PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
				}
			}
			catch (Exception ex)
			{
				// displays the error message.
				PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
				// log message.
				try
				{
					Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
				}
				catch
				{
					PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
				}			
			}		
		}

		//**************************************************************************		
		/// <summary>
		/// 
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		/// <Author> Son HT, Dec 30, 2004</Author>
		private void c1FlexGridRole_AfterRowColChange(object sender, RangeEventArgs e)
		{
			const string METHOD_NAME = THIS + ".c1FlexGridRole_AfterRowColChange()";
			try
			{
				// Get RoleID
				int intRowSel = c1FlexGridRole.RowSel;
				// if user change selected row
				if(e.OldRange.r1 != e.NewRange.r1)
				{
					// Check Empty row
					if (intRowSel > 0)
					{
						// Get data display on column 1 of Role
						string strRoleID = c1FlexGridRole.GetDataDisplay(c1FlexGridRole.RowSel,INT_START);
						// load checking of tree
						if(strRoleID.Length > 0)
						{
							LoadCheckingOfProtect(int.Parse(strRoleID));
						}
					}
				}
			}
			catch (PCSException ex)
			{
				// displays the error message.
				PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
				// log message.
				try
				{
					Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
				}
				catch
				{
					PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
				}
			}
			catch (Exception ex)
			{
				// displays the error message.
				PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
				// log message.
				try
				{
					Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
				}
				catch
				{
					PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
				}			
			}
		}
		
		/// <summary>
		/// 
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		/// <Author> Son HT, Dec 30, 2004</Author>
		private void btnSave_Click(object sender, EventArgs e)
		{
			// Code Inserted Automatically

			#region Code Inserted Automatically

			this.Cursor = Cursors.WaitCursor;

			#endregion Code Inserted Automatically

			
			const string METHOD_NAME = THIS + ".btnSave_Click()";
			// if user doesn't change data on form
			if(!blnIsModified) 
			{
				// Code Inserted Automatically
				#region Code Inserted Automatically
				this.Cursor = Cursors.Default;
				#endregion Code Inserted Automatically																						
				return;
			}
			try
			{
				for(int i = INT_START; i < c1FlexGridProtect.Rows.Count; i++)
				{
					// is leaf
					// if (int.Parse(c1FlexGridProtect.GetDataDisplay(i,INT_POS_PARENT_CHILD).ToString()) == IS_LEAF) 
					// store
				{
					// Store to dataset
					Sys_RightVO voSysRight = new Sys_RightVO();
					voSysRight.Menu_EntryID = int.Parse(c1FlexGridProtect.GetDataDisplay(i,INT_POS_MENU_ENTRY).ToString());
					voSysRight.RoleID = int.Parse(c1FlexGridRole.GetDataDisplay(c1FlexGridRole.RowSel,INT_START).ToString());
					voSysRight.Permission = int.Parse(c1FlexGridProtect.GetDataDisplay(i,INT_POS_PERMISSION).ToString());
					StoreToDataSet(voSysRight);
				}
				}
				StoreDatabase();
				blnIsModified = false;
				PCSMessageBox.Show(ErrorCode.MESSAGE_AFTER_SAVE_DATA,MessageBoxButtons.OK);
			}
			catch (PCSException ex)
			{
				// displays the error message.
				PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
				// log message.
				try
				{
					Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
				}
				catch
				{
					PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
				}
			}
			catch (Exception ex)
			{
				// displays the error message.
				PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
				// log message.
				try
				{
					Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
				}
				catch
				{
					PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
				}
			}

			// Code Inserted Automatically

			#region Code Inserted Automatically

			this.Cursor = Cursors.Default;

			#endregion Code Inserted Automatically

			
		}
		
		//**************************************************************************		
		/// <summary>
		/// 
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		/// <Author> Son HT, Dec 30, 2004</Author>
		private void GrantRoleProtect_Closing(object sender, CancelEventArgs e)
		{
			const string METHOD_NAME = THIS + ".GrantRoleProtect_Closing()";
			// if user doesn't change data on form
			if(!blnIsModified) return;
			try
			{
//				for(int i = INT_START; i < c1FlexGridProtect.Rows.Count; i++)
//				{
//					// is leaf
//					if (int.Parse(c1FlexGridProtect.GetDataDisplay(i,INT_POS_PARENT_CHILD).ToString()) == (int)MenuParentChildEnum.LeafMenu) 
//					{
//						// Store to dataset
//						Sys_RightVO voSysRight = new Sys_RightVO();
//						voSysRight.Menu_EntryID = int.Parse(c1FlexGridProtect.GetDataDisplay(i,INT_POS_MENU_ENTRY).ToString());
//						voSysRight.RoleID = int.Parse(c1FlexGridRole.GetDataDisplay(c1FlexGridRole.RowSel,INT_START).ToString());
//						voSysRight.Permission = int.Parse(c1FlexGridProtect.GetDataDisplay(i,INT_POS_PERMISSION).ToString());
//						StoreToDataSet(voSysRight);
//					}
//				}
				// Show answer messase to store data into database
				DialogResult enumDialog = PCSMessageBox.Show(ErrorCode.MESSAGE_QUESTION_STORE_INTO_DATABASE,MessageBoxButtons.YesNoCancel,MessageBoxIcon.Question);
				if(enumDialog == DialogResult.Yes)
				{
					// StoreDatabase();
					btnSave_Click(sender,e);
				}
				else if(enumDialog == DialogResult.Cancel)
				{
					e.Cancel = true;
				}

			}
			catch (PCSException ex)
			{
				// displays the error message.
				PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
				// log message.
				try
				{
					Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
				}
				catch
				{
					PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
				}
			}
			catch (Exception ex)
			{
				// displays the error message.
				PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
				// log message.
				try
				{
					Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
				}
				catch
				{
					PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
				}
			}		
		}
		
		/// <summary>
		/// 
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		/// <Author> Son HT, Dec 30, 2004</Author>
		private void c1FlexGridProtect_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Space)
			{
				c1FlexGridProtect_Click(c1FlexGridProtect,null);
			}
		}

		#endregion
	}
}